using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Xml;
using System.IO;
using System.Collections;

namespace Reminder
{
    public partial class NewEvent : Form
    {
        private RemindersDocument _doc;

        Event _event;

        public NewEvent(RemindersDocument doc)
        {
            _doc = doc;
            InitializeComponent();
        }

        public Event Event
        {
            get { return _event; }
            set
            {
                _event = value;
                txtComment.Text = _event.Name;
                TimeSpan interval = _event.Interval;
                txtTime.Text = interval.TotalSeconds.ToString();
            }
        }
        
        private void btnOk_Click(object sender, EventArgs e)
        {            
            TimeSpan interval = new TimeSpan(0, 0, Convert.ToInt32(txtTime.Text));

            if (_event!=null)
            {                
                _event.Name = txtComment.Text;
                _event.Interval = interval;
                _doc.SetDirty();
                _doc.Save();
            }
            else
            {                
                _event = new Event();
                _event.Name = this.txtComment.Text;
                _event.Interval = interval;
                _doc.AddEvent(_event);
            }

            base.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }
    }
}